<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout :project-number="projectNumber">
      <d-forms label-width="200rpx">
        <d-forms-item label="签证批次" :input="form.visaBatch"></d-forms-item>
        <d-forms-item :type="DFormInputType.DATE" label="签证时间" :input="form.visaTime"></d-forms-item>
        <d-forms-item :type="DFormInputType.AMOUNT" label="汇总金额" :input="form.visaAmount"></d-forms-item>
        <view>
          <view class="form-title-1">签证上传</view>
          <d-card>
            <pm-file-upload readonly :files="form.visaUpload"></pm-file-upload>
          </d-card>
        </view>
        <view>
          <view class="form-title-1">签证上传</view>
          <d-card>
            <d-forms-item disabled :input="form.remarks"></d-forms-item>
          </d-card>
        </view>
        <view>
          <view class="form-title-1">物品清单</view>
          <view v-for="(item, idx) in form.itemList" :key="item.id" class="mb10">
            <d-card>
              <d-forms-item disabled label="产品/设备名称" :input="item.name"></d-forms-item>
              <d-forms-item disabled label="品牌/厂商">
                <pm-firm-select disabled :firm-id="item.firm"></pm-firm-select>
              </d-forms-item>
              <d-forms-item disabled label="型号" :input="item.model"></d-forms-item>
              <d-forms-item disabled label="总数" :input="item.num"></d-forms-item>
              <d-forms-item disabled label="已申请数量" :input="item.appliedNum"></d-forms-item>
              <view>
                <view class="form-title-2">参数规格</view>
                <d-forms-item disabled :input="item.specifications"></d-forms-item>
              </view>
              <view>
                <view class="form-title-2">备注</view>
                <d-forms-item disabled :input="item.remarks"></d-forms-item>
              </view>
            </d-card>
          </view>
        </view>
      </d-forms>
    </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">

import {useWorkVisaApi} from "@/api/pm/project/workVisa";
import {DFormInputType} from "@/utils/enum";

const triggered = ref<boolean>(false);
const initForm = {
  projectNumber: null,
  visaBatch: null,
  visaTime: null,
  visaAmount: {
    source: null,
    parsedValue: null,
  },
  visaUpload: null,
  remarks: null,
  id: null,
  createTime: null,
  itemList: null,
}
const form = ref<WorkVisaForm>({} as any);
function getDetail() {
  if (rowId.value) {
    triggered.value = true;
    useWorkVisaApi().getEmploymentVisa(rowId.value).then(res => {
      if (res.code === 0) {
        form.value = res.data || initForm
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

const projectNumber = ref<string>(null);
const rowId = ref<string>(null);
onLoad((query) => {
  projectNumber.value = query['project_number'];
  rowId.value = query['id'];
  getDetail();
})
</script>

<style scoped lang="scss">

</style>
